﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LibrarySolution.ComMethod;
using LibrarySolution.DAO.基础;
using LibrarySolution.DAO.委托;
using LibrarySolution.Model.基础;

namespace LibrarySolution.Frm
{
    public partial class FrmYhjb : Form
    {
        #region 属性
        YhJbDao yhjbDao = new YhJbDao();
        JbxxDetail jbxxDetail = new JbxxDetail();
        Delegates delegates = new Delegates();
        private static FrmYhjb Instance;
        #endregion

        #region 构造器
        public FrmYhjb()
        {
            InitializeComponent();
            delegates.refreshLBEvent += new Delegates.refreshLBEventHandler(delegates_refreshLBEvent);
            refreshDtgv();
        }
        #endregion

        #region 事件
        public static FrmYhjb GetInstance()
        {
            if (Instance == null || Instance.IsDisposed)
            {
                Instance = new FrmYhjb();
                Instance.MdiParent = GlobalVar.frmMain;
                GlobalVar.frmMain.panel1.Controls.Add(Instance);
            }
            Instance.BringToFront();
            return Instance;
        }

        private void TstripBtnDel_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要删除选中项", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation,
                MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
            {
                string jbCode = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString();
                yhjbDao.DelSelectRow(jbCode);
                refreshDtgv();
            }
        }

        private void TstripBtnRef_Click(object sender, EventArgs e)
        {
            refreshDtgv();
        }

        private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            jbxxDetail = new JbxxDetail();
            jbxxDetail.yhjb_code = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString();
            GlobalVar.JbxxDetail = yhjbDao.getJbxxByCode(jbxxDetail);
            FrmYhjbModify.IsModify = true;
            FrmYhjbModify.GetInstance(delegates).ShowDialog();
        }

        private void TstripBtnAdd_Click(object sender, EventArgs e)
        {
            FrmYhjbModify.IsModify = false;
            FrmYhjbModify.GetInstance(delegates).ShowDialog();
        }
        #endregion

        #region 方法
        void delegates_refreshLBEvent()
        {
            refreshDtgv();
        }
        void refreshDtgv()
        {
            DataTable dt = null;
            JbxxDetail jbxxDetail = new JbxxDetail();
            dt = yhjbDao.getDataTable(jbxxDetail);
            dataGridView1.DataSource = dt;
            dataGridView1.Refresh();
        }
        #endregion
    }
}
